#include "AIComponent.h"
#include "AIPackages/TestPackage.h"
#include "Transform.h"

mtBEGIN(AIComponentDef)
	mtVARIABLE(fraction);
	mtCONSTRUCTOR();
mtEND

mtBEGIN(AIComponent)
	mtBASE(ECS::Component);
	mtCONSTRUCTOR();
	mtMETHOD(initWith);
	mtMETHOD(onStart);
	mtMETHOD(onUpdate);
mtEND;

bool AIComponent::initWith(AIComponentDef* def)
{
	_actor = new ai::AIActor();
	_actor->setUserData(this);
	_actor->addPackage(new TestPackage());
	return true;
}

void AIComponent::onUpdate()
{
	_actor->update();
}

Fraction* AIComponent::getFraction() const
{
	return _fraction;
}

void AIComponent::setFraction(Fraction* fraction)
{
	_fraction = fraction;
}

AIComponent::AIComponent()
{

}

void AIComponent::onStart()
{
	prevPosition = ECS::Vec2<int>(getComponent<Transform>()->getPosition()) + ECS::Vec2<int>(1,1);
}
